<?php

namespace app\shop\model\store;

use app\common\model\store\Remarks as RemarksModel;
use Lvht\GeoHash;

/**
 * 门店模型
 */
class Remarks extends RemarksModel
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'app_id',
        'update_time',
    ];

    /**
     * 获取列表数据
     */
    public function getList($data = null)
    {
        $model = $this;

        $list = $model->where('is_delete', '=', '0')
            ->order(['create_time' => 'desc'])
            ->paginate($data);
        return $list;
    }

    /**
     * 获取所有门店列表
     */
    public static function getAllList()
    {
        return (new self)->where('is_delete', '=', '0')
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select();
    }

    public static function detail($where)
    {
        $filter = is_array($where) ? $where : ['id' => $where];
        return (new static())->where(array_merge(['is_delete' => 0], $filter))->find();
    }

    /**
     * 新增记录
     */
    public function add($data)
    {
        $data = $this->createData($data);
        return self::create($data);
    }

    /**
     * 编辑记录
     */
    public function edit($data)
    {
        return $this->save($this->createData($data));
    }

    /**
     * 软删除
     */
    public function setDelete($where)
    {
        return self::update(['is_delete' => 1], $where);
    }

    /**
     * 创建数据
     */
    private function createData($data)
    {
        $data['app_id'] = self::$app_id;
        return $data;
    }

}
